import { showDetailPage, initToolButtonList } from '@/utils';
function linkToSummary(affairId, subject, app, subApp, objectId, subObjectId, link, thirdApp) {
  var url = _ctxPath + "/collaboration/collaboration.do?method=summary&openFrom=listDone&affairId=" + affairId + "&showTab=true";;
  if (app === 6) {//会议应用
    url = _ctxPath + "/meeting.do?method=view&meetingId=" + objectId + "&showTab=true";
  } else if (app === 29) {//会议室
    url = _ctxPath + "/meetingroom.do?method=roomAudit&groupId=" + objectId + "&showTab=true";;
  } else if (app == 4) {//G6公文
    if (subApp === 1 || subApp === 2 || subApp === 3 || subApp === 4) {//G6新公文-发文/收文/签收/交换
      url = _ctxPath + "/govdoc/govdoc.do?method=summary&openFrom=listDone&affairId=" + affairId;
    } else if (subApp === 19 || subApp === 20 || subApp === 21) {//G6老公文-发文/收文/签收
      url = _ctxPath + "/edocController.do?method=detailIFrame&from=Done&affairId=" + affairId;
    } else if (subApp == 22) {//G6老公文-交换
      url = _ctxPath + "/exchangeEdoc.do?method=edit&id=" + subObjectId + "&affairId=" + affairId + "&modelType=sent";
    } else if (subApp == 23) {//G6老公文-签收
      url = _ctxPath + "/exchangeEdoc.do?method=edit&id=" + subObjectId + "&affairId=" + affairId + "&modelType=received";
    } else if (subApp == 24) {//G6老公文-登记
      url = _ctxPath + "/edocController.do?method=edocRegisterDetail&forwardType=registered&registerId=" + objectId;
      if (subObjectId != null && subObjectId != "") {
        url += "&recieveId=" + subObjectId;
      }
    } else if (subApp == 34) {//G6老公文-分发
      url = _ctxPath + "/edocController.do?method=detailIFrame&from=Sent&&affairId=" + affairId;
    }
  } else if (app == 81 || app == 39 || thirdApp) {//模板审批-走链接地址，建议其他类型可以走自己的link||三方待办
    url = _ctxPath + link;
  }
  return url;
}
export default {
  data() {
    return {
      dataType: null
    };
  },
  methods: {
    handleRowClick(data) {
      const key = data.affairId || data.id;
      const url = linkToSummary(key, null, data.applicationCategoryKey, data.applicationSubCategoryKey, data.objectId, data.subObjectId, data.link, data.thirdApp);
      showDetailPage(url, key);
    },
    initToolButtonList(needButtonList, globalParam, scanIndex) {
      if (needButtonList.length > 0) {
        this.toolButtonList = initToolButtonList(needButtonList, globalParam);
      }
      scanIndex !== undefined && this.toolButtonList.splice(scanIndex, 0, this.smartCodeBtnInfo);
    },
    // 配置
    currentDataClickHandle(resetTableData) {
      this.disabledToolbar();
      this.dataType = '0';
      this.$nextTick(resetTableData);
    },
    dumpDataClickHandle(resetTableData) {
      this.disabledToolbar();
      this.dataType = '1';
      this.$nextTick(resetTableData);
    },
    disabledToolbar() {
      this.toolButtonList = this.toolButtonList.map(item => {
        if (!['currentData', 'dumpData'].includes(item.id)) {
          item.disabled = true;
        }
        return item;
      });
    },
  },
};
